package PageClassTable;

import page.Page;
import page.PageClass;
import utils.JdbcUtils;

import javax.swing.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

public class QueryPageClass {
    public static void init(int power){
        JFrame frame=new JFrame();
        String info = JOptionPane.showInputDialog(frame,"要查询的分类为:","输入",JOptionPane.WARNING_MESSAGE);
        if(!info.isEmpty()){
            if(PageClass.sameName(info)){
                JOptionPane.showMessageDialog(frame,"分类名不存在");
            }else{
                List<Map<String, Object>> re = JdbcUtils.JdbcQuery(PageClass.sql_queryClass,info);
                int id=0;
                for(Map<String,Object> map : re){
                    for(String key : map.keySet()) {
                        if(key.equals("page_class_id"))id= (int) map.get(key);
                    }
                }
                PageClass.jssum();
                JOptionPane.showMessageDialog(frame,"分类编号:"+id+"\n分类名为:"+info+"\n该分类下文章数量:"+JdbcUtils.JdbcQuery(Page.sql_query_class_sum,info).size());
            }
        }
    }
}
